<?php


namespace App\server;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class JwtServer
{
    /**
     * jwt加密
     * @param $uid
     * @param int $exprie
     * @return string
     */
    public static function jwtEncode($uid,$exprie = 7200)
    {
        $key = '2008a_hyzf';
        $payload = [
            'uid'=>$uid,
            'time'=>time()+$exprie
        ];

        $jwt = JWT::encode($payload, $key, 'HS256');
        return $jwt;
    }

    /**
     * jwt解密
     * @param $jwt
     * @return array
     */
    public static function JwtDecode($jwt)
    {
        $key = '2008a_hyzf';
        $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
        $decoded_array = (array) $decoded;
        return $decoded_array;
    }
}
